package org.jetnuke.modules.admin.content;

import java.util.HashMap;
import java.util.Iterator;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.velocity.VelocityContext;
import org.jetnuke.common.ActionForward;
import org.jetnuke.common.IAction;
import org.jetnuke.common.IAdminInfo;
import org.jetnuke.common.IModuleInfo;
import org.jetnuke.common.IUserInfo;
import org.jetnuke.dao.DataAccessDriver;
import org.jetnuke.entities.PagesCategories;

public class ListPages implements IAction {

	public ActionForward exec(HttpServletRequest request,
			HttpServletResponse response, VelocityContext vc, IModuleInfo info,
			String op, IUserInfo ui, IAdminInfo ai) throws Exception {

		if (ai == null || (!ai.IsSuperUser() && !ai.isAdminContent()))
			return null;//Error;

		Iterator it =DataAccessDriver.getInst().newPagesCatDAO().selectAll().iterator(); 
			//pages_categoriesPeer.doSelect(new Criteria()).iterator();
		HashMap mp = new HashMap();
		while (it.hasNext()) {
			PagesCategories cat = (PagesCategories) it.next();
			mp.put(new Integer(cat.getCID()), cat.getTITLE());
		}
		mp.put(new Integer(-1), "None");
		vc.put("rows", DataAccessDriver.getInst().newPagesDAO().selectAll());// pagesPeer.doSelect(new Criteria()));
		vc.put("cat_map", mp);
		return new ActionForward(op, info);
	}
}
